package com.blog.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 师晓峰
 * @version V1.0
 * @date 2023/9/10 16:06
 * @Description:
 *  日期工具类
 */
public class DateUtil {
    /**
     * 获取当前精确到秒的字符串
     */
    public static String getCurrentDateStr(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
        return sdf.format(date);
    }

    /**
     * 按照格式转换字符串
     * @param date
     * @param format
     * @return
     */
    public static String formatDate(Date date,String format){
        String result = "";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        if (date != null){
            result = sdf.format(date);
        }
        return result;
    }

}
